#include "timer.h"

static volatile unsigned long s_TickCnt = 0;

//设定一个定时器并启动
void	StartTimer(Timer* tm,unsigned long t)
{
	tm->IntervalTime = t;
	tm->BaseTime = s_TickCnt;
}

//判断一个定时器是否已经溢出
int		TimeOut(Timer* tm)
{
	if(s_TickCnt - tm->BaseTime >= tm->IntervalTime)
	{
		return 1;
	}
	return 0;
}

//剩余时间
int     TimerLeft(Timer* tm)
{
    return tm->BaseTime + tm->IntervalTime - s_TickCnt;
}

//获取tick
unsigned long GetTimeTick(void)
{
	return s_TickCnt;
}

void SysTick_Handler()
{
	s_TickCnt++;
}
